<script type='text/javascript' src="/statics/js/swfupload/swfupload.js"></script>
<script type='text/javascript' src="/statics/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="/statics/js/swfupload/fileprogress.js"></script>
<script type="text/javascript" src="/statics/js/swfupload/handlers_font.js"></script>
<script type='text/javascript' src="/statics/js/artdialog/skins/default.css"></script>
<script type='text/javascript' src="/statics/js/artdialog/artDialog.js"></script>

<div class="user-center-head"><?php echo L('repair_return')?></div>
<table class="table-list">
  <tbody>
    <tr>
      <th width="40%"><?php echo L('goods_name')?>
        </td>
      <th width="20%"><?php echo L('goods_price');?>
        </td>
      <th width="20%"><?php echo L('goods_number');?>
        </td>
      <th width="20%"><?php echo L('goods_total');?>
        </td>
    </tr>
    <tr>
      <td><a href="<?php echo url('/product', 'id='.$orderInfo['product_id']);?>" target="_blank"><?php echo $orderInfo['product_name']?></a></td>
      <td><?php echo currency($orderInfo['pay_price'])?></td>
      <td><?php echo $orderInfo['qty']?></td>
      <td><?php echo currency($orderInfo['total_amount'])?></td>
    </tr>
  </tbody>
</table>
<form action="" method="post" enctype="multipart/form-data">
<div class="user-center-head"><?php echo L('request_type')?></div>
  <table border="0" cellpadding="0" cellspacing="0" class="orderpurchasetable">
    <tbody>
      <tr>
        <td width="20%"><i class="asterisk">*</i><?php echo L('request_type')?>:</td>
        <td width="80%" class="fwleix">
		  <?php $purchaseType = OrderModel::$purchaseType;
            foreach ($purchaseType as $type_id => $type_name):
          ?>
          <label style="margin-right:20px;">
            <input type="radio" name="purchase_type" value="<?php echo $type_id;?>" <?php if($type_id==1)echo'checked';?>>
            <?php echo L($type_name);?>
          </label>
          <?php endforeach;?>
        </td>
      </tr>
      <tr>
        <td width="20%"><i class="asterisk">*</i><?php echo L('request_number')?>:</td>
        <td width="80%"><input type="text"  name="number" id="delivery_number" title="<?php echo isset($orderInfo['qty']) ? $orderInfo['qty'] : 1?>" value="<?php echo isset($orderInfo['qty']) ? $orderInfo['qty'] : 1?>" pattern="int" alt="<?php echo L('inputnumber')?>" /></td>
      </tr>
      <tr>
        <td width="20%"><i class="asterisk">*</i><?php echo L('question_desc')?>:</td>
        <td width="80%"><textarea name="description" cols="60" rows="5" pattern="required" alt="<?php echo L('inputquestion')?>"></textarea>
          <p><?php echo L('inputquestion_tip')?></p>
          <input type="file" name="photo_name"  />
<!--          <input type="file" name='myfile' id="myfile" onchange="input1.value=this.value" style="display:none" />-->
          <p><?php echo L('canmanyuploadimg')?></p>
          <p><?php echo L('upload image description');?></p>
        </td>
      </tr>
      <tr>
        <td width="20%"><i class="asterisk">*</i><?php echo L('contact_name')?>:</td>
        <td width="80%"><input type="text" name="contact_name" value="<?php echo isset($orderInfo['delivery_first_name']) ? $orderInfo['delivery_first_name'] : null?><?php echo isset($orderInfo['delivery_last_name']) ?  ' '.$orderInfo['delivery_last_name'] : null?>" pattern="required" alt="<?php echo L('inputconectinfo')?>"/></td>
      </tr>
      <tr>
        <td width="20%"><i class="asterisk">*</i><?php echo L('phone')?>:</td>
        <td width="80%"><input type="text" name="contact_phone" value="<?php echo isset($orderInfo['delivery_phone']) ? $orderInfo['delivery_phone'] : null?>" pattern="required" alt="<?php echo L('inputphone')?>"/></td>
      </tr>
      <tr>
        <td width="20%"><i class="asterisk">*</i><?php echo L('email')?>:</td>
        <td width="70%"><input type="text" name="contact_email" value="<?php echo isset($orderInfo['delivery_email']) ? $orderInfo['delivery_email'] : null?>" pattern="email" alt="<?php echo L('inputemail')?>"/></td>
      </tr>
      <tr>
        <td width="20%"></td>
        <td width="80%">
          <input type="hidden" name="order_id" value="<?php echo $orderInfo['order_id']?>" />
          <input type="hidden" name="product_name" value="<?php echo $orderInfo['product_name']?>" />
          <input type="submit" name="dosubmit" value="<?php echo L('saveuser')?>" class="btn btn-middle" />
        </td>
      </tr>
    </tbody>
  </table>
</form>
<script type="text/javascript">
$(function(){
	$('#delivery_number').blur(function(){
		if($(this).val()>$(this).attr('title')){
			$(this).val($(this).attr('title'));
		}
		});
});
var swfu;
window.onload = function () {
	swfu = new SWFUpload({
		// Backend Settings
		upload_url: "<?php echo U('public/swfupload_ajax');?>",
		post_params: {"PHPSESSID": "<?php echo session_id();?>"},

		file_size_limit : "2 MB",	// 2MB
		file_types : "*.jpg;*.jpge;*.png;*.gif",
		file_types_description : "JPG Images",
		file_upload_limit : 5,
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,

		// Button Settings
		button_placeholder_id : "upload",
		button_width: 50,
		button_height: 21,
		button_text : "<?php echo L('begin_upload')?>",
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,

		// Flash Settings
		flash_url : "/statics/js/swfupload/swfupload.swf",

		custom_settings : {
			upload_target : "show"
		},
		// Debug Settings
		debug: false
	});
};

function del_img(id)
{
	//删除数组元素.
	Array.prototype.remove=function(dx)
	{
	    if(isNaN(dx)||dx>this.length){return false;}
	    for(var i=0,n=0;i<this.length;i++)
	    {
	        if(this[i]!=this[dx])
	        {
	            this[n++]=this[i]
	        }
	    }
	    this.length-=1
	}
	//在数组中获取指定值的元素索引
	Array.prototype.getIndexByValue= function(value)
	{
	    var index = -1;
	    for (var i = 0; i < this.length; i++)
	    {
	        if (this[i] == value)
	        {
	            index = i;
	            break;
	        }
	    }
	    return index;
	}
	var photo_name = $('#photo_name').val();
	photo_name = photo_name.substring(0,photo_name.length-1);
	var arr = photo_name.split(',');
	var key = 0;
	for(var i=0;i<arr.length;i++){
		if(arr[i].indexOf(id)>0){
			key = i;
		}
	}
	arr.remove(key);
	if(arr.length>0)
	{
		//如果没有全部删除则不为空
		$('#photo_name').val(arr.join(',')+',')
		$("#a"+id).remove();
		var focus_photo = $('#focus_photo').val();
		if(focus_photo.indexOf(id)>0)
		{
			var photo_ar = arr.join(',');
			if(photo_ar!='')
			{
				p_arr = photo_ar.split(',');
				var head = p_arr[0].substring(0,p_arr[0].indexOf('.'));
				var footer = p_arr[0].substring(p_arr[0].indexOf('.'));
				var thumb = $('#thumb').val();
				$('#focus_photo').val(head+footer);
				$('img').each(function(){
					var src = $(this).attr("src");
					if(src.indexOf(head+thumb+footer)>0)
					{
						$(this).addClass('current');
						return;
					}
				});
			}
		}
	}else{
		//如果图片全部删除则值为空
		$('#photo_name').val("");
		$('#focus_photo').val("");
		$("#a"+id).remove();
	}
}
function show_bigimg(filepath)
{
	art.dialog({title:'View',fixed:true, content:'<img src="'+filepath+'" onload="$(this).LoadImage(true, 500, 500,\'/statics/images/nopic.gif\');"/>'});	
}
</script>